perm filename NOTES.IMB[LSP,JRA]1 blob sn#249364 filedate 1976-11-28 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	.SEC(Imperative constructs in LISP)
C00007 ENDMK
C⊗;
.SEC(Imperative constructs in LISP)
.SS(Introduction)
Though the applicative subset of LISP is rich and powerful, it is
often conveinent to  have access to another type of language
constuct called an %2imperative%1. 

As its name implies, an imperative construct has the appearance of a command.
For that reason imperative commands are called statements rather than expressions
since the implication is that it is the %2effect%1 of the command which
is important; and its value, if it has one, is  of secondary importance.
For example, most programming languages have sequencing commands: "first
do %3S%41%1, then do %3S%42%1"; that might be written "%3S%41%3;#S%42%1",
where %3S%41%1 and %3S%42%1 are statements.
The nature of imperatives is somewhat illusory, since sequencing can be
expressed in out applicative subset:

.BEGIN CENTER;SELECT 3;

S%41%3;S%42%1### is### %3λ[[] S%42%3][S%41%3]
.END

Here we depend on the order of evaluation  which LISP uses; 
since %3S%41%1 is the argument, that statement is evaluated first; 
then %3S%42%1 is evaluated. The value of either statement is ignored.


A domain which is thought to be the  province of imperatives is
that of the assignment statement. We will discuss assignment
in {yonss(P37)}, but the intent of such a statement, written:

.BEGIN CENTER;TURN OFF "←";

<identifier> ← <expression>
.END
is to think of the <identifier> as a "box" and the intent of the
assignment is to put the value of the <expressions> in the "box".
Yet, function application can encompass many of the applications
of assignment. Recall our definitions of %3length%1 and %3length%41%1:

.BEGIN CENTERIT;SELECT 3;group;

←length[l] <= [null[l] → 0; %et%* → add1[length[rest[l]]]]

←length%41%*[l] <= length%9'%*[l;0]

←length%9'%*[l;x] <= [null[l] → x; %et%* → length%9'%*[rest[l];add1[x]]]
.END
The variable %3x%1 is being used as a "box" or "accumulator" ⊗↑[Moo#xx]↑
to accumulate length of the list.
We will show in {yonss(P37)} that
%3length%41%1 can be translated into a
program using several imperative features: statements, sequencing, assignments,
and an imperative control regime called %2iteration%1.
We will study iterative control in {yonss(P37)} and {yonss(P253)}
but again it can be showing that iterative control can be
translated into recursive control ⊗↑[McC#60]↑.

What then is the point of imperatives?  The most important point for
our purposes is "convenience". There are alogrithms which are most
nautrally thought of in terms of sequences of statements and iteration.
and there are many lessons to be learned by careful analysis of
natural implementations of imperative constructs. We are not looking for
a minimal language, we are looking for a  useful programming tool.
One of the most useful places for imperative constructs is in
area of non-local variables, using assignment statements to pass information
across applicative boundaries. This technique is called  using 
side-effects. It may very well be that the most distinstive
features of imperative constructs are involved with their
side-effect aspects. 

***I/O***